package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.LeaveStudent;
import cn.wolfcode.crm.query.LeaveStudentQueryObject;
import cn.wolfcode.crm.service.ILeaveStudentService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("leaveStudent")
public class LeaveStudentController {

    @Autowired
    private ILeaveStudentService service;

    @PermissionName("学员流失首页")
    @RequiresPermissions("leaveStudent:index")
    @RequestMapping("index")
    public String index(){
        return "leaveStudent/list";
    }

    @PermissionName("学员流失列表")
    @RequiresPermissions("leaveStudent:list")
    @ResponseBody
    @RequestMapping("list")
    public PageResult list(LeaveStudentQueryObject qo){
        PageResult result = service.query(qo);
        return result;
    }
    @PermissionName("学员流失添加记录")
    @RequiresPermissions("leaveStudent:save")
    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(LeaveStudent leaveStudent){
        try{
            service.save(leaveStudent);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("操作失败");
        }
        return new JsonResult();
    }

    //根据学员id查流失学员的姓名和退款金额
    @ResponseBody
    @RequestMapping("queryByIdForNameAndRefundAmount")
    public LeaveStudent queryByIdForNameAndRefundAmount(Long stuId){
        return service.queryByIdForNameAndRefundAmount(stuId);
    }

    @ResponseBody
    @RequestMapping("changeState")
    public JsonResult changeState(Long id){
        try{
            service.changeState(id);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("审核失败");
        }
        return new JsonResult();
    }


}
